package com.sub.project.mall.contorller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import java.util.List;
import java.util.Arrays;

import com.sub.common.utils.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sub.framework.aspectj.lang.annotation.Log;
import com.sub.framework.aspectj.lang.enums.BusinessType;
import com.sub.project.mall.domain.OmsCostmer;
import com.sub.project.mall.service.IOmsCostmerService;
import com.sub.framework.web.controller.BaseController;
import com.sub.framework.web.domain.AjaxResult;
import com.sub.common.utils.poi.ExcelUtil;
import com.sub.framework.web.page.TableDataInfo;

/**
 * 客户管理Controller
 *
 * @author sub
 * @date 2020-08-23
 */
@RestController
@RequestMapping("/mall/costmer" )
public class OmsCostmerController extends BaseController {
    @Autowired
    private IOmsCostmerService omsCostmerService;

    /**
     * 查询客户管理列表
     */
    @PreAuthorize("@ss.hasPermi('mall:costmer:list')" )
    @GetMapping("/list" )
    public TableDataInfo list(OmsCostmer omsCostmer) {
        startPage();
        QueryWrapper<OmsCostmer> queryWrapper = new QueryWrapper<OmsCostmer>();
                    if (StringUtils.isNotBlank(omsCostmer.getBusinessName())){
            queryWrapper.like("business_name" ,omsCostmer.getBusinessName());
        }
            if(StringUtils.isNotBlank(omsCostmer.getPhone())){
     queryWrapper.eq("phone" ,omsCostmer.getPhone());
}
    if(StringUtils.isNotBlank(omsCostmer.getCounty())){
     queryWrapper.eq("county" ,omsCostmer.getCounty());
}
            List<OmsCostmer> list = omsCostmerService.list(queryWrapper);
        return getDataTable(list);
    }

    /**
     * 导出客户管理列表
     */
    @PreAuthorize("@ss.hasPermi('mall:costmer:export')" )
    @Log(title = "客户管理" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(OmsCostmer omsCostmer) {
        QueryWrapper<OmsCostmer> queryWrapper = new QueryWrapper<OmsCostmer>(omsCostmer);
        List<OmsCostmer> list = omsCostmerService.list(queryWrapper);
        ExcelUtil<OmsCostmer> util = new ExcelUtil<OmsCostmer>(OmsCostmer. class);
        return util.exportExcel(list, "costmer" );
    }

    /**
     * 获取客户管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:costmer:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(omsCostmerService.getById(id));
    }

    /**
     * 新增客户管理
     */
    @PreAuthorize("@ss.hasPermi('mall:costmer:add')" )
    @Log(title = "客户管理" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OmsCostmer omsCostmer) {
        return toAjax(omsCostmerService.save(omsCostmer) ? 1 : 0);
    }

    /**
     * 修改客户管理
     */
    @PreAuthorize("@ss.hasPermi('mall:costmer:edit')" )
    @Log(title = "客户管理" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OmsCostmer omsCostmer) {
        return toAjax(omsCostmerService.updateById(omsCostmer) ? 1 : 0);
    }

    /**
     * 删除客户管理
     */
    @PreAuthorize("@ss.hasPermi('mall:costmer:remove')" )
    @Log(title = "客户管理" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(omsCostmerService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
